﻿//
// Copyright 2008-2011 by Burt Harris
// Licensed under the Microsoft Public License (Ms-PL)
// See: http://www.codeplex.com/yaml/license
//

namespace YaTools.Yaml.UnitTests
{
    using System.Diagnostics;
    using System.Diagnostics.Contracts;
    using System.IO;
    using Microsoft.Scripting;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class CommonTest
    {
        /// <summary>
        ///Gets or sets the test dumper which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }


        [Conditional("DEBUG")]
        protected void DebugLine(string format, params object[] args)
        {
            Contract.Requires(format != null);
            Contract.Requires(args != null);

            Debug.WriteLine(string.Format(format, args));
        }

        [Conditional("DEBUG")]
        protected void DebugInput(string path, string yaml)
        {
            Contract.Requires(path != null);
            Contract.Requires(yaml != null);

            Debug.WriteLine("");
            Debug.WriteLine(path, "File");

            int lineNumber = 1;
            using (var reader = new StringReader(yaml))
            {
                string line;
                while ((line = reader.ReadLine()) != null) // Show line numbers
                {
                    DebugLine("{0:0000}:  {1}", lineNumber++,
                              Utility.DebugDisplay(line));
                }
                DebugLine("");
            }
        }

        public static YamlSyntaxErrorException Error(ErrorId id)
        {
            string message = id.GetMessage();
            return new YamlSyntaxErrorException(message, string.Empty, string.Empty, string.Empty,
                                                SourceSpan.None, id.ErrorNumber, Severity.Error);
        }

        #region Additional test attributes

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //

        #endregion
    }
}